#region Copyright RenGuiYou. All rights reserved.
//=====================================================
// NeatlyFrameWork
// Author:      RenGuiyou
// Feedback: 	mailto:750539605@qq.com
//=====================================================
#endregion

using System.Collections.Generic;
using System.Diagnostics;

namespace Neatly
{
    public static class Developer
    {
        #region 加载bundle
        private static Dictionary<string, Stopwatch> m_LoadBundleDic;
        public static Dictionary<string, Stopwatch> LoadBundleDic => m_LoadBundleDic ??= new Dictionary<string, Stopwatch>();

        [Conditional("DEVELOP")]
        public static void StartLoadBundle(string name)
        {
            if (!LoadBundleDic.TryGetValue(name, out var watch))
            {
                watch = new Stopwatch();
                LoadBundleDic.Add(name, watch);
            }
            watch.Start();
        }
        [Conditional("DEVELOP")]
        public static void EndLoadBundle(string name)
        {
            LoadBundleDic.TryGetValue(name, out var watch);
            watch.Stop();
        }
        #endregion

        #region 加载AssetFromBundle
        private static Dictionary<string, Stopwatch> m_LoadAssetDic;
        public static Dictionary<string, Stopwatch> LoadAssetDic => m_LoadAssetDic ??= new Dictionary<string, Stopwatch>();

        [Conditional("DEVELOP")]
        public static void StartLoadAsset(string name)
        {
            if (!LoadAssetDic.TryGetValue(name, out var watch))
            {
                watch = new Stopwatch();
                LoadAssetDic.Add(name, watch);
            }
            watch.Start();
        }
        [Conditional("DEVELOP")]
        public static void EndLoadAsset(string name)
        {
            LoadAssetDic.TryGetValue(name, out var watch);
            watch.Stop();
        }
        [Conditional("DEVELOP")]
        public static void StartLoadAtlas(string name)
        {
            name = GetAtlasNameKey(name);
            if (!LoadAssetDic.TryGetValue(name, out var watch))
            {
                watch = new Stopwatch();
                LoadAssetDic.Add(name, watch);
            }
            watch.Start();
        }
        [Conditional("DEVELOP")]
        public static void EndLoadAtlas(string name)
        {
            name = GetAtlasNameKey(name);
            LoadAssetDic.TryGetValue(name, out var watch);
            watch.Stop();
        }
        private static string GetAtlasNameKey(string name)
        {
            return $"图集:{name}";
        }
        #endregion

    }
}
